package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ZcTransport;
import com.ruoyi.system.service.IZcTransportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 运输工具Controller
 * 
 * @author ruoyi
 * @date 2023-06-26
 */
@Controller
@RequestMapping("/system/transport")
public class ZcTransportController extends BaseController
{
    private String prefix = "system/transport";

    @Autowired
    private IZcTransportService zcTransportService;

    @RequiresPermissions("system:transport:view")
    @GetMapping()
    public String transport()
    {
        return prefix + "/transport";
    }

    /**
     * 查询运输工具列表
     */
    @RequiresPermissions("system:transport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZcTransport zcTransport)
    {
        startPage();
        List<ZcTransport> list = zcTransportService.selectZcTransportList(zcTransport);
        return getDataTable(list);
    }

    /**
     * 导出运输工具列表
     */
    @RequiresPermissions("system:transport:export")
    @Log(title = "运输工具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZcTransport zcTransport)
    {
        List<ZcTransport> list = zcTransportService.selectZcTransportList(zcTransport);
        ExcelUtil<ZcTransport> util = new ExcelUtil<ZcTransport>(ZcTransport.class);
        return util.exportExcel(list, "运输工具数据");
    }

    /**
     * 新增运输工具
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存运输工具
     */
    @RequiresPermissions("system:transport:add")
    @Log(title = "运输工具", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZcTransport zcTransport)
    {
        return toAjax(zcTransportService.insertZcTransport(zcTransport));
    }

    /**
     * 修改运输工具
     */
    @RequiresPermissions("system:transport:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZcTransport zcTransport = zcTransportService.selectZcTransportById(id);
        mmap.put("zcTransport", zcTransport);
        return prefix + "/edit";
    }

    /**
     * 修改保存运输工具
     */
    @RequiresPermissions("system:transport:edit")
    @Log(title = "运输工具", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZcTransport zcTransport)
    {
        return toAjax(zcTransportService.updateZcTransport(zcTransport));
    }

    /**
     * 删除运输工具
     */
    @RequiresPermissions("system:transport:remove")
    @Log(title = "运输工具", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zcTransportService.deleteZcTransportByIds(ids));
    }
}
